<!DOCTYPE html>
<html lang="en">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
    <script type="text/javascript"
            src="https://webapi.amap.com/maps?v=1.4.15&key=38ec219a062bbf92f1f3ccd9a574752b">
    </script>
    <script src="https://a.amap.com/jsapi_demos/static/demos/requirejs/require.js"
            data-main="https://a.amap.com/jsapi_demos/static/demos/requirejs/require-init"></script>
    <script src="https://webapi.amap.com/ui/1.0/main.js?v=1.0.11"></script>
    <style>

    </style>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
</head>
<body>
<div id="app">
    <div class="content-header">
        <h1>首页
            <small>公司分布图</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane label="分布图" name="first">
                    <div id="map"></div>
                </el-tab-pane>
                <el-tab-pane label="详细信息" name="second">
                    <div class="filter-container">
                        <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;"
                                  class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPageByqueryString()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row
                              ref="multipleTable">
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="address" label="公司地址" align="center"></el-table-column>
                        <el-table-column prop="longitude" label="所在经度" align="center"></el-table-column>
                        <el-table-column prop="latitude" label="所在维度" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                                background
                                class="pagiantion"
                                @current-change="handleCurrentChange"
                                @size-change="handleSizeChange"
                                :current-page="pagination.currentPage"
                                :page-size="pagination.pageSize"
                                layout="total, prev, pager, next, sizes, jumper"
                                :total="pagination.total">
                        </el-pagination>
                    </div>
                </el-tab-pane>
            </el-tabs>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增地址" :visible.sync="dialogFormVisible" :before-close="findPage2">
                    <div id="add_address"></div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    var vue = new Vue({
            el: '#app',
            data: {
                address: {},
                longitude: {},
                latitude:[],
                loading: true,
                activeName: 'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,
                    pageSize: 10,
                    total: 100,
                    queryString: null,
                },
                dataList: [],//列表数据
                dialogFormVisible: false,//控制添加窗口显示/隐藏
                dialogFormVisible4Edit: false//控制编辑窗口显示/隐藏
            },
            created() {
                this.findPage();
                activeName:'first';
                $("#map").html("<iframe frameborder='0' src=map.html height='500' width='100%'></iframe>");
                $("#add_address").html("<iframe frameborder='0' src=add-address-map.html height='500' width='100%'></iframe>");
            },

            methods: {
                // 重置
                resetForm() {
                    this.activeName = 'first';
                    this.dialogFormVisible=false;
                    this.findPage();
                },
                // 弹出添加窗口
                handleCreate() {
                    $("#add_address").html("<iframe frameborder='0'  src=add-address-map.html height='500' width='100%'></iframe>")
                    this.dialogFormVisible = true;
                },

                // 删除
                handleDelete(row) {
                    this.$confirm("确定要删除此数据吗?","提示",{
                        confirmButtonText: '确定删除',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(()=>{
                        axios.post("/company/delete.do?id=" + row.id).then((resp)=>{
                            if (resp.data.flag) {
                                this.$message.success(resp.data.message)
                            } else {
                                this.$message.error(resp.data.message)
                            }
                        }).finally(()=>{
                            this.findPage();
                        })
                    }).catch(()=>{
                        this.$message.info("已取消删除操作")
                    })
                },

                //条件查询
                findPageByqueryString() {
                    this.pagination.currentPage = 1;
                    this.findPage();
                },
                //分页查询
                findPage() {
                    //分页参数
                    var param = {
                        currentPage: this.pagination.currentPage,//页码
                        pageSize: this.pagination.pageSize,//每页显示的记录数
                        queryString: this.pagination.queryString//查询条件
                    };
                    //请求后台
                    axios.post("/company/findPage.do", param).then((res) => {
                        //为模型数据赋值，基于VUE的双向绑定展示到页面
                        this.dataList = res.data.rows;
                        this.pagination.total = res.data.total;
                    });
                },
                findPage2(done){
                    this.findPage();
                    done();
                },

                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage = currentPage;
                    this.findPage();
                },
                //切换每页显示条数
                handleSizeChange(pageSize){
                    this.pagination.pageSize = pageSize;
                    this.findPage();
                },
                //切换标签页
                handleClick(){
                    this.findPage();
                    $("#map").html("<iframe frameborder='0' src=map.html height='500' width='100%'></iframe>");

                }
            }
        }
    );

</script>
</html>